<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      table {
        border-collapse: collapse;
        margin: 50px auto;
      }
      tr {
        text-align: center;
      }
      td {
        height: 40px;
        cursor: pointer; /*鼠标手形*/
      }
      th {
        background-color: rgb(0, 153, 203);
        color: white;
        height: 50px;
      }
      tbody tr:nth-child(2n) {
        background-color: #999;
      }
      tbody tr:nth-child(2n + 1) {
        background-color: #eee;
      }
    </style>
  </head>
  <body>
    <table border="1px" width="600px">
      <thead>
        <tr>
          <th>序号</th>
          <th>姓名</th>
          <th>课程</th>
          <th>成绩</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>001</td>
          <td>张三</td>
          <td>前端开发</td>
          <td>98</td>
        </tr>
        <tr>
          <td>002</td>
          <td>李四</td>
          <td>Java开发</td>
          <td>99</td>
        </tr>
        <tr>
          <td>003</td>
          <td>王五</td>
          <td>Python开发</td>
          <td>68</td>
        </tr>
        <tr>
          <td>004</td>
          <td>王麻子</td>
          <td>ui设计</td>
          <td>28</td>
        </tr>
        <tr>
          <td>005</td>
          <td>胖虎</td>
          <td>大数据开发</td>
          <td>90</td>
        </tr>
        <tr>
          <td>006</td>
          <td>铁蛋</td>
          <td>就业指导</td>
          <td>88</td>
        </tr>
      </tbody>
    </table>
  </body>
  <script>
    var trs = document
      .getElementsByTagName("tbody")[0]
      .getElementsByTagName("tr");
    for (var i in trs) {
        //鼠标移入高亮显示
      trs[i].onmouseover = function () {
        this.style.backgroundColor = "yellow";
      };
      //鼠标移出移除高亮显示
      trs[i].onmouseout = function () {
        this.style.backgroundColor = "";
      };
    }
  </script>
</html>
